package com.hh.eduservice.controller;


import com.alibaba.excel.EasyExcel;
import com.hh.commonutils.Result;
import com.hh.eduservice.entity.EduSubject;
import com.hh.eduservice.entity.subject.OneSubject;
import com.hh.eduservice.entity.subject.TwoSubject;
import com.hh.eduservice.service.EduSubjectService;
import com.hh.eduservice.utils.EduSubjectListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.ArrayList;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author huhuan
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    @PostMapping("/addSubject")
    public Result addSubject(MultipartFile file){
        //将EduSubjectService作为参数传递，保证监听器内能进行数据库操作
        eduSubjectService.addSubject(file, eduSubjectService);
        return Result.success();
    }

    @GetMapping("/subjectListTree")
    public Result subjectListTree(){
        ArrayList<OneSubject> treeList = eduSubjectService.getTreeList();
//        return Result.success().data("data", treeList);
        return Result.success().data("list", treeList);
    }
}

